// 地址 平铺数组转树形
export const treeDataTranslate = (data: any, id = "areaId", pid = 'parentId') => {
    if (data.length === 0) return []
    var res = []
    var temp: any = {}

    for (var i = 0; i < data.length; i++) {
        temp[data[i][id]] = data[i]
    }
    for (var k = 0; k < data.length; k++) {
        if (temp[data[k][pid]] && data[k][id] !== data[k][pid]) {
            if (!temp[data[k][pid]]['children']) {
                temp[data[k][pid]]['children'] = []
            }
            if (!temp[data[k][pid]]['level']) {
                temp[data[k][pid]]['level'] = 1
            }
            data[k]['level'] = temp[data[k][pid]].level + 1
            temp[data[k][pid]]['children'].push(data[k])
        } else {
            res.push(data[k])
        }
    }
    return res
}
